/**
 * Created by WT-SUN on 2017/3/16.
 */

$(function () {
    $('#useState').combobox('setValue', useState);
    $('#resType').combobox('setValue', resType);
    $('#parentResourceId').combotree({
        url: ROOT_PATH+'/permission/resource/selectAllByUserId.shtml',
        required: true,
        onLoadSuccess:function (node, data) {
            var parentText = window.parent.getTreeNodeText();
            if (parentText=='0'){
                parentText=parentText=="0"?'顶级目录':parentText;
                $("#parentResourceId").combotree("setValue",{id:'0',text:parentText});
            }
        }
    });

});
/**
 * 清空表单
 */
function clearForm() {
    $("#resourceForm").form('clear');
    $('#id').val(resourceId);
}
/**
 * 提交表单
 */
function submitForm() {
    $('#resourceForm').form('submit', {
        url: ROOT_PATH + '/permission/resource/updateByPrimaryKeySelective.shtml',
        onSubmit: function (param) {
            if (!$(this).form('validate')) {
                layer.alert('请正确填写信息', {icon: 5});
            }
            return $(this).form('validate');
        },
        success: function (result) {
            result = $.parseJSON(result);
            if (result.success) {
                layer.msg('保存成功', {
                    icon: 1,
                    time: 1000 //2秒关闭（如果不配置，默认是3秒）
                }, function () {
                    var indexp = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(indexp); //再执行关闭
                });
                window.parent.reLoadData();
            }
            else {
                layer.msg('保存失败', {
                    icon: 2,
                    time: 1000
                });
            }
        }
    });
}